home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CPOPUPME
/
STRINGUT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-19
|
2KB
|
58 lines
#include "defs.h"
#include "StringUtil.h"
/*****************************************************************************/
void EllipseString( Str255 s, Int16 width)
{
/*
if the string fits inside the given number of pixels, fine -- do nothing
and return.
if not, return a string that does fit, with ellipses representing the
deleted characters. ellipses are generated by pressing option-semicolon.
*/
Int16 len;
len = FitText( (Ptr)&s[1], s[0], width);
if (len < s[0]) /* string was trimmed */
{
s[0] = '╔'; /* last char is ellipse */
}
} /* EllipseString */
/*****************************************************************************/
Int16 FitText( register Ptr text, register Int16 length, register Int16 width)
/*
calculate how much of text will fit into width.
Ptr - points to text
length - desired length of text
width - available width in pixels
returns number of chars that will fit
*/
{ register Int16 currWidth;
do
{
currWidth = TextWidth( text, 0, length);
if (currWidth <= width) break;
}
while (--length > 0);
return length;
} /* FitText */
/*****************************************************************************/
Int16 toupper(Int16 c)
{
return (((c >= 'a') && (c <= 'z')) ? (c ^ 0x20) : c);
} /* toupper */
/*****************************************************************************/
Int16 tolower(Int16 c)
{
return (((c >= 'A') && (c <= 'Z')) ? (c ^ 0x20) : c);
} /* tolower */
/*****************************************************************************/